package com.xiaohao.healthrecords.controller;

import com.xiaohao.healthrecords.entity.Payment;
import com.xiaohao.healthrecords.entity.ResponseResult;
import com.xiaohao.healthrecords.service.PaymentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("payment")
public class PaymentController {
    @Autowired
    private PaymentService paymentService;

    @GetMapping("{id}")
    public ResponseResult<Payment> query(@PathVariable Integer id) {
        return ResponseResult.success(paymentService.query(new Payment().setId(id)));
    }

    @GetMapping
    public ResponseResult<List<Payment>> query(Payment payment) {
        return ResponseResult.success(paymentService.queryList(payment));
    }

    @PostMapping
    public ResponseResult<Void> update(@RequestBody Payment payment) {
        if (paymentService.update(payment) != 0) {
            return ResponseResult.success();
        } else {
            return ResponseResult.error();
        }
    }
    @DeleteMapping("{id}")
    public ResponseResult<Void> delete(@PathVariable Integer id) {
        paymentService.delete(id);
        return ResponseResult.success();
    }
}
